package com.bor.gb.admin.ui;

import com.bor.gb.db.repositories.GuideRepository;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import ru.xpoft.vaadin.DiscoveryNavigator;

@Component
@Scope("prototype")
public class MyUI extends UI {

    protected static final String PLACE = "Places";
    protected static final String ARTICLE = "Articles";
    @Autowired
    private transient ApplicationContext applicationContext;
    @Autowired
    private transient GuideRepository repository;

    @Override
    protected void init(final VaadinRequest request) {

        final VerticalLayout content = new VerticalLayout();


        setContent(content);

        getPage().setTitle("Navigation Example");

        // Create a navigator to control the views


        MenuBar menubar = new MenuBar();
        content.addComponent(menubar);
        final HorizontalLayout vCont = new HorizontalLayout();

        content.addComponent(vCont);

        final DiscoveryNavigator navigator = new DiscoveryNavigator(getUI().getCurrent(), vCont);

        navigator.setErrorView(ErrorView.class);
        UI.getCurrent().setNavigator(navigator);


        for (final String viewName : new String[]{"ArticleView", "PlaceView"}) {

            menubar.addItem(viewName, selectedItem -> {
                        navigator.navigateTo(viewName);
                    }
            );
        }

    }
}
